package com.app.shortvideo.ui

import android.animation.ObjectAnimator
import android.os.Bundle
import android.view.animation.DecelerateInterpolator
import com.app.shortvideo.config.Constant
import com.app.shortvideo.databinding.ActivitySplashBinding
import com.app.shortvideo.base.BaseActivity
import com.app.library.base.LibViewModel
import com.app.library.utils.CheckVirtual
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.DeviceUtils
import kotlin.system.exitProcess

class SplashActivity : BaseActivity<ActivitySplashBinding, LibViewModel>() {
    private val startRunnable = {
//        if (Session.isSessionOpen() && Session.userSession?.canEnterMain() == true) {
        MainActivity.startMain(this)
//        } else {
//            AccountEntranceActivity.start(this)
//        }
        finish()
    }

    override fun initData(savedInstanceState: Bundle?) {
    }

    override fun initView() {
        binding.tvVersion.text = "v${AppUtils.getAppVersionName()}"
        val anim = ObjectAnimator.ofFloat(binding.ivLogo, "alpha", 0f, 1f)
        anim.duration = 1200
        anim.interpolator = DecelerateInterpolator()
        anim.start()
        if (Constant.getServerType() == Constant.SERVER_PRO && (DeviceUtils.isEmulator() || CheckVirtual.isRunInVirtual)) {
            finish()
            exitProcess(0)
        } else {
            binding.root.postDelayed(startRunnable, 2000)
        }
    }
}